<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>flatmenubuttonrenderer.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_ui_flatmenubuttonrenderer.js.html">flatmenubuttonrenderer.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2008 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Similiar functionality of {@link goog.ui.MenuButtonRenderer},
<a name="line17"></a> * but inherits from {@link goog.ui.FlatButtonRenderer} instead of
<a name="line18"></a> * {@link goog.ui.CustomButtonRenderer}. This creates a simpler menu button
<a name="line19"></a> * that will look more like a traditional &lt;select&gt; menu.
<a name="line20"></a> *
<a name="line21"></a> */
<a name="line22"></a>
<a name="line23"></a>goog.provide(&#39;goog.ui.FlatMenuButtonRenderer&#39;);
<a name="line24"></a>
<a name="line25"></a>goog.require(&#39;goog.dom&#39;);
<a name="line26"></a>goog.require(&#39;goog.style&#39;);
<a name="line27"></a>goog.require(&#39;goog.ui.FlatButtonRenderer&#39;);
<a name="line28"></a>goog.require(&#39;goog.ui.INLINE_BLOCK_CLASSNAME&#39;);
<a name="line29"></a>goog.require(&#39;goog.ui.Menu&#39;);
<a name="line30"></a>goog.require(&#39;goog.ui.MenuButton&#39;);
<a name="line31"></a>goog.require(&#39;goog.ui.MenuRenderer&#39;);
<a name="line32"></a>goog.require(&#39;goog.ui.registry&#39;);
<a name="line33"></a>
<a name="line34"></a>
<a name="line35"></a>
<a name="line36"></a>/**
<a name="line37"></a> * Flat Menu Button renderer. Creates a simpler version of
<a name="line38"></a> * {@link goog.ui.MenuButton} that doesn&#39;t look like a button and
<a name="line39"></a> * doesn&#39;t have rounded corners. Uses just a &lt;div&gt; and looks more like
<a name="line40"></a> * a traditional &lt;select&gt; element.
<a name="line41"></a> * @constructor
<a name="line42"></a> * @extends {goog.ui.FlatButtonRenderer}
<a name="line43"></a> */
<a name="line44"></a>goog.ui.FlatMenuButtonRenderer = function() {
<a name="line45"></a>  goog.ui.FlatButtonRenderer.call(this);
<a name="line46"></a>};
<a name="line47"></a>goog.inherits(goog.ui.FlatMenuButtonRenderer, goog.ui.FlatButtonRenderer);
<a name="line48"></a>goog.addSingletonGetter(goog.ui.FlatMenuButtonRenderer);
<a name="line49"></a>
<a name="line50"></a>
<a name="line51"></a>/**
<a name="line52"></a> * Default CSS class to be applied to the root element of components rendered
<a name="line53"></a> * by this renderer.
<a name="line54"></a> * @type {string}
<a name="line55"></a> */
<a name="line56"></a>goog.ui.FlatMenuButtonRenderer.CSS_CLASS =
<a name="line57"></a>    goog.getCssName(&#39;goog-flat-menu-button&#39;);
<a name="line58"></a>
<a name="line59"></a>
<a name="line60"></a>/**
<a name="line61"></a> * Returns the button&#39;s contents wrapped in the following DOM structure:
<a name="line62"></a> *    &lt;div class=&quot;goog-inline-block goog-flat-menu-button&quot;&gt;
<a name="line63"></a> *        &lt;div class=&quot;goog-inline-block goog-flat-menu-button-caption&quot;&gt;
<a name="line64"></a> *          Contents...
<a name="line65"></a> *        &lt;/div&gt;
<a name="line66"></a> *        &lt;div class=&quot;goog-inline-block goog-flat-menu-button-dropdown&quot;&gt;
<a name="line67"></a> *          &amp;nbsp;
<a name="line68"></a> *        &lt;/div&gt;
<a name="line69"></a> *    &lt;/div&gt;
<a name="line70"></a> * Overrides {@link goog.ui.FlatButtonRenderer#createDom}.
<a name="line71"></a> * @param {goog.ui.Control} control Button to render.
<a name="line72"></a> * @return {!Element} Root element for the button.
<a name="line73"></a> * @override
<a name="line74"></a> */
<a name="line75"></a>goog.ui.FlatMenuButtonRenderer.prototype.createDom = function(control) {
<a name="line76"></a>  var button = /** @type {goog.ui.Button} */ (control);
<a name="line77"></a>  var classNames = this.getClassNames(button);
<a name="line78"></a>  var attributes = {
<a name="line79"></a>    &#39;class&#39;: goog.ui.INLINE_BLOCK_CLASSNAME + &#39; &#39; + classNames.join(&#39; &#39;)
<a name="line80"></a>  };
<a name="line81"></a>  var element = button.getDomHelper().createDom(&#39;div&#39;, attributes,
<a name="line82"></a>      [this.createCaption(button.getContent(), button.getDomHelper()),
<a name="line83"></a>       this.createDropdown(button.getDomHelper())]);
<a name="line84"></a>  this.setTooltip(
<a name="line85"></a>      element, /** @type {!string}*/ (button.getTooltip()));
<a name="line86"></a>  this.setAriaStates(button, element);
<a name="line87"></a>  return element;
<a name="line88"></a>};
<a name="line89"></a>
<a name="line90"></a>
<a name="line91"></a>/**
<a name="line92"></a> * Takes the button&#39;s root element and returns the parent element of the
<a name="line93"></a> * button&#39;s contents.
<a name="line94"></a> * @param {Element} element Root element of the button whose content
<a name="line95"></a> * element is to be returned.
<a name="line96"></a> * @return {Element} The button&#39;s content element (if any).
<a name="line97"></a> * @override
<a name="line98"></a> */
<a name="line99"></a>goog.ui.FlatMenuButtonRenderer.prototype.getContentElement = function(element) {
<a name="line100"></a>  return element &amp;&amp; /** @type {Element} */ (element.firstChild);
<a name="line101"></a>};
<a name="line102"></a>
<a name="line103"></a>
<a name="line104"></a>/**
<a name="line105"></a> * Takes an element, decorates it with the menu button control, and returns
<a name="line106"></a> * the element.  Overrides {@link goog.ui.CustomButtonRenderer#decorate} by
<a name="line107"></a> * looking for a child element that can be decorated by a menu, and if it
<a name="line108"></a> * finds one, decorates it and attaches it to the menu button.
<a name="line109"></a> * @param {goog.ui.Control} button Menu button to decorate the element.
<a name="line110"></a> * @param {Element} element Element to decorate.
<a name="line111"></a> * @return {Element} Decorated element.
<a name="line112"></a> * @override
<a name="line113"></a> */
<a name="line114"></a>goog.ui.FlatMenuButtonRenderer.prototype.decorate = function(button, element) {
<a name="line115"></a>  // TODO(user): MenuButtonRenderer uses the exact same code.
<a name="line116"></a>  // Refactor this block to its own module where both can use it.
<a name="line117"></a>  var menuElem = goog.dom.getElementsByTagNameAndClass(
<a name="line118"></a>      &#39;*&#39;, goog.ui.MenuRenderer.CSS_CLASS, element)[0];
<a name="line119"></a>  if (menuElem) {
<a name="line120"></a>    // Move the menu element directly under the body, but hide it first; see
<a name="line121"></a>    // bug 1089244.
<a name="line122"></a>    goog.style.setElementShown(menuElem, false);
<a name="line123"></a>    button.getDomHelper().getDocument().body.appendChild(menuElem);
<a name="line124"></a>
<a name="line125"></a>    // Decorate the menu and attach it to the button.
<a name="line126"></a>    var menu = new goog.ui.Menu();
<a name="line127"></a>    menu.decorate(menuElem);
<a name="line128"></a>    button.setMenu(menu);
<a name="line129"></a>  }
<a name="line130"></a>
<a name="line131"></a>  // Add the caption if it&#39;s not already there.
<a name="line132"></a>  var captionElem = goog.dom.getElementsByTagNameAndClass(
<a name="line133"></a>      &#39;*&#39;, goog.getCssName(this.getCssClass(), &#39;caption&#39;), element)[0];
<a name="line134"></a>  if (!captionElem) {
<a name="line135"></a>    element.appendChild(
<a name="line136"></a>        this.createCaption(element.childNodes, button.getDomHelper()));
<a name="line137"></a>  }
<a name="line138"></a>
<a name="line139"></a>  // Add the dropdown icon if it&#39;s not already there.
<a name="line140"></a>  var dropdownElem = goog.dom.getElementsByTagNameAndClass(
<a name="line141"></a>      &#39;*&#39;, goog.getCssName(this.getCssClass(), &#39;dropdown&#39;), element)[0];
<a name="line142"></a>  if (!dropdownElem) {
<a name="line143"></a>    element.appendChild(this.createDropdown(button.getDomHelper()));
<a name="line144"></a>  }
<a name="line145"></a>
<a name="line146"></a>  // Let the superclass do the rest.
<a name="line147"></a>  return goog.ui.FlatMenuButtonRenderer.superClass_.decorate.call(this, button,
<a name="line148"></a>      element);
<a name="line149"></a>};
<a name="line150"></a>
<a name="line151"></a>
<a name="line152"></a>/**
<a name="line153"></a> * Takes a text caption or existing DOM structure, and returns it wrapped in
<a name="line154"></a> * an appropriately-styled DIV.  Creates the following DOM structure:
<a name="line155"></a> *    &lt;div class=&quot;goog-inline-block goog-flat-menu-button-caption&quot;&gt;
<a name="line156"></a> *      Contents...
<a name="line157"></a> *    &lt;/div&gt;
<a name="line158"></a> * @param {goog.ui.ControlContent} content Text caption or DOM structure to wrap
<a name="line159"></a> *     in a box.
<a name="line160"></a> * @param {goog.dom.DomHelper} dom DOM helper, used for document interaction.
<a name="line161"></a> * @return {Element} Caption element.
<a name="line162"></a> */
<a name="line163"></a>goog.ui.FlatMenuButtonRenderer.prototype.createCaption = function(content,
<a name="line164"></a>                                                                  dom) {
<a name="line165"></a>  return dom.createDom(&#39;div&#39;,
<a name="line166"></a>      goog.ui.INLINE_BLOCK_CLASSNAME + &#39; &#39; +
<a name="line167"></a>      goog.getCssName(this.getCssClass(), &#39;caption&#39;), content);
<a name="line168"></a>};
<a name="line169"></a>
<a name="line170"></a>
<a name="line171"></a>/**
<a name="line172"></a> * Returns an appropriately-styled DIV containing a dropdown arrow element.
<a name="line173"></a> * Creates the following DOM structure:
<a name="line174"></a> *    &lt;div class=&quot;goog-inline-block goog-flat-menu-button-dropdown&quot;&gt;
<a name="line175"></a> *      &amp;nbsp;
<a name="line176"></a> *    &lt;/div&gt;
<a name="line177"></a> * @param {goog.dom.DomHelper} dom DOM helper, used for document interaction.
<a name="line178"></a> * @return {!Element} Dropdown element.
<a name="line179"></a> */
<a name="line180"></a>goog.ui.FlatMenuButtonRenderer.prototype.createDropdown = function(dom) {
<a name="line181"></a>  // 00A0 is &amp;nbsp;
<a name="line182"></a>  return dom.createDom(&#39;div&#39;, {
<a name="line183"></a>    &#39;class&#39;: goog.ui.INLINE_BLOCK_CLASSNAME + &#39; &#39; +
<a name="line184"></a>        goog.getCssName(this.getCssClass(), &#39;dropdown&#39;),
<a name="line185"></a>    &#39;aria-hidden&#39;: true
<a name="line186"></a>  }, &#39;\u00A0&#39;);
<a name="line187"></a>};
<a name="line188"></a>
<a name="line189"></a>
<a name="line190"></a>/**
<a name="line191"></a> * Returns the CSS class to be applied to the root element of components
<a name="line192"></a> * rendered using this renderer.
<a name="line193"></a> * @return {string} Renderer-specific CSS class.
<a name="line194"></a> * @override
<a name="line195"></a> */
<a name="line196"></a>goog.ui.FlatMenuButtonRenderer.prototype.getCssClass = function() {
<a name="line197"></a>  return goog.ui.FlatMenuButtonRenderer.CSS_CLASS;
<a name="line198"></a>};
<a name="line199"></a>
<a name="line200"></a>
<a name="line201"></a>// Register a decorator factory function for Flat Menu Buttons.
<a name="line202"></a>goog.ui.registry.setDecoratorByClassName(
<a name="line203"></a>    goog.ui.FlatMenuButtonRenderer.CSS_CLASS,
<a name="line204"></a>    function() {
<a name="line205"></a>      // Uses goog.ui.MenuButton, but with FlatMenuButtonRenderer.
<a name="line206"></a>      return new goog.ui.MenuButton(null, null,
<a name="line207"></a>          goog.ui.FlatMenuButtonRenderer.getInstance());
<a name="line208"></a>    });
</pre>


</body>
</html>
